package com.ssm.gbq.dao.impl;

import com.ssm.gbq.dao.DoctorDao;
import com.ssm.gbq.mapper.DoctorMapper;
import com.ssm.gbq.model.Doctor;
import gbq.ssm.utils.PageBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class DoctorDaoImpl implements DoctorDao {

    @Autowired
    private DoctorMapper doctorMapper;

    public PageBounds<Doctor> openDoctorTable(String doctorName,String createTimeMax,String createTimeMin, int currentPage, int pageSize) throws Exception {
        final int totalSize = doctorMapper.countByExample(doctorName, createTimeMax, createTimeMin);
        PageBounds<Doctor> pageBounds = new PageBounds<Doctor>(currentPage, totalSize, pageSize);
        List<Doctor> list = doctorMapper.selectByLimitPage(doctorName, createTimeMax, createTimeMin, pageBounds.getOffset(), pageBounds.getPageSize());
        pageBounds.setPageList(list);
        return pageBounds;
    }

    public List<Doctor> selectAllDoctor() {
        return doctorMapper.selectAllDoctor();
    }

    public void deleteDoctorByIds(List<Integer> ids) throws Exception {
        doctorMapper.deleteByPrimaryKey(ids);
    }
  public int deleteDoctorById(Integer id) {
      return doctorMapper.deleteDoctorById(id);
  }

    public int addDoctor(Doctor doctor) throws Exception {
        return doctorMapper.addDoctor(doctor);
    }

    public int updateDoctor(Doctor doctor) {
        return doctorMapper.updateDoctor(doctor);
    }

    public Doctor findById(Integer id) {
        Doctor doctor=  doctorMapper.findById(id);
        return  doctor;
    }
}
